package com.pc.tas.web;

import com.pc.tas.export.expfilelist.ExpFileList;
import com.pc.tas.export.expfilelist.ExpFileListService;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ExpFileListController {
	@Autowired
	private ExpFileListService es;
	
	@RequestMapping("/expfilelist/list" )
	@ResponseBody
	public String list(@RequestParam String expType,@RequestParam int offset,@RequestParam int limit) throws Exception {
		JSONObject jo = new JSONObject();
		JSONArray jps= new JSONArray();
		try{
			List<ExpFileList> expFileLists = es.getListByExpType(Integer.parseInt(expType),offset,limit);
			for(ExpFileList efl : expFileLists) {
				jps.put(efl.toJSON());
			}		
		}catch(Exception e){
			e.printStackTrace();
		}
		jo.put("records", jps);
		jo.put("total", jps.length());
		return jo.toString();		
	}

	
}
